package com.system.controller;

import com.system.pojo.Roles;
import com.system.service.RolesService;
import com.system.util.JSONUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
public class RolesController {
    JSONUtil jsonUtil = new JSONUtil();
    @Autowired
    private RolesService rolesService;

    @RequestMapping("selectRoleTable")
    @ResponseBody
    public String selectRoleTable() {
        List<Roles> list = rolesService.select(null);
        return jsonUtil.toJson("0", list, "");
    }

    @RequestMapping("insertRole")
    @ResponseBody
    public String insertRole(@RequestBody List<Roles> roless) {
        System.out.println("添加角色：" + roless.get(0).toString());
        return jsonUtil.toJson("0", rolesService.insert(roless.get(0)), "");
    }

    @RequestMapping("deleteRole")
    @ResponseBody
    public String deleteRole(@RequestBody String id) {
        return rolesService.delete(id);
    }

    @RequestMapping("insertRoleMenus")
    @ResponseBody
    public String insertRoleMenus(@RequestBody List<Roles> roless) {
        return rolesService.insertRoleMenus(roless);
    }

    public RolesService getRoleService() {
        return rolesService;
    }

    public void setRolesService(RolesService rolesService) {
        this.rolesService = rolesService;
    }
}
